package Action;

import java.sql.Connection;
import java.sql.PreparedStatement;


import Bean.ProductBean;
import Utils.*;

public class Product {
	public boolean insertProduct(ProductBean bean, Connection conn, String _lang) {
		String sql = "insert into products (id, name" + _lang
				+ ", createdate, description" + _lang + ",detail" + _lang
				+ ",thumbnail,picture,price" + _lang + ",showhome)"
				+ " values (?,?,?,?,?,?,?,?,?)";
		PreparedStatement stmt = null;
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, bean.getId());
			stmt.setString(2, bean.getName());
			stmt.setString(3, Utils.StringUtil.convertDateForSQL(bean.getCreateDate().toString()));
			stmt.setString(4, bean.getDescription());
			stmt.setString(5, bean.getDetail());
			stmt.setString(6, bean.getThumbnail());
			stmt.setString(7, bean.getPicture());
			stmt.setString(8, bean.getPrice());
			stmt.setInt(9, bean.getShowHome());

			stmt.executeUpdate();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (stmt != null) {
				try {
					stmt.close();
				} catch (Exception e) {
				}
			}
		}
	}
}
